<?php

class Airline extends CI_Model {

    function index() {
        $q = $this->db->get('maskapai');
        return $q->result();
    }

    function get_array() {
        $q = $this->db->get('maskapai');
        foreach ($q->result_array() as $row) {
            $data{$row['id']} = $row['name'];
        }
        return $data;
    }

    function show($id) {
        $this->db->where('id', $id);
        $q = $this->db->get('admin_bank');
        return $q;
    }

    function edit($id) {
        $this->db->where('id', $id);
        $q = $this->db->get('maskapai');
        return $q->result();
    }

    function create($name, $image, $date) {
        $data = array(
            'name' => $name,
            'image' => $image,
            'date' => $date,
        );
        $this->db->insert('maskapai', $data);
        redirect('airlines/index');
    }

    function update($id, $name, $image) {
        if ($image == null) {
            $data = array(
                'name' => $name,
            );
        } else {
            $data = array(
                'name' => $name,
                'image' => $image,
            );
        }
        $this->db->where('id', $id);
        $this->db->update('maskapai', $data);
        redirect('airlines/index');
    }

    function delete($id) {
        $this->db->where('id', $id);
        $this->db->delete('maskapai');
        redirect('airlines/index');
    }

    function get_maskapai($id) {
        $this->db->where('id', $id);
        $q = $this->db->get('maskapai');
        foreach ($q->result() as $rows):
            return $data = $rows->name;
        endforeach;
    }

    function get_image($id) {
        $this->db->where('id', $id);
        $q = $this->db->get('maskapai');
        foreach ($q->result() as $rows):
            return $data = $rows->image;
        endforeach;
    }
    
    function get_idm($name){
        $this->db->where('name', $name);
        $q = $this->db->get('maskapai');
        foreach ($q->result() as $rows):
            return $data = $rows->id;
        endforeach;
    }

}

?>
